package comm.util;

import android.content.Context;
import android.util.Log;

import java.lang.reflect.Field;
import java.util.Locale;

/**
 * @Description
 * @Author imchen
 * @CreateTime 2019/11/11 15:11
 */
public class Localx {

    private static final String FIRST_LANGUAGE="zh_CN";

    public static Object getDefault(){
        Locale locale=Locale.getDefault();

        Log.d("Localx", "Localx: "+locale.toString());
        return locale;
    }

    @Override
    public String toString(){
        return FIRST_LANGUAGE;
    }

    public static void setDefaultLanguage(Context context, String language){
        Locale locale=new Locale(language);
        try {
            Class clz=context.getClassLoader().loadClass("java.util.Locale$NoImagePreloadHolder");
            Field field=clz.getDeclaredField("defaultLocale");
            field.setAccessible(true);
            field.set(null,locale);
        } catch (Exception e) {
            e.printStackTrace();
        }
        Log.d("iLogger","After reflect field:--> "+Locale.getDefault());
    }

    public void demo(Context context,String language){
        setDefaultLanguage(context,language);
    }
}
